package LO_102;

import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

import LCommon.TreeNode;

public class Solution {
	public List<List<Integer>> levelOrder(TreeNode root) {
		List<List<Integer>> ansList = new LinkedList<List<Integer>>();
		
		
		Queue<TreeNode> lq = new LinkedList<TreeNode>();
		lq.add(root);
	
		while (!lq.isEmpty()) {
			List<Integer> tempList = new LinkedList<Integer>();
			int size = lq.size();
			for (int i = 0; i < size; i++) {
				TreeNode tempNode = lq.poll();
				tempList.add(tempNode.val);
				if (tempNode.left != null) {
					lq.add(tempNode.left);
				}
				if (tempNode.right != null) {
					lq.add(tempNode.right);
				}
			}
			ansList.add(tempList);
		}
		
		return ansList;
	}
}
